package com.idol.framework.handler;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * @author Supreme_Sir
 * @version 1.0
 * @className HandlerMappingContainer
 * @description 处理器映射器 Method 调用 invoke 所需参数值包装类
 * @date 2020/10/31 20:48
 **/
public class Handler {
    /**
     * 方法所属对象
     */
    private Object object;
    /**
     * 方法
     */
    private Method method;
    /**
     * 为了支持正则表达式，所以采用 Patter 来存储 URL，
     * 当然如果不想支持正则，可直接使用 String
     */
    private Pattern pattern;
    /**
     * 参数顺序
     */
    private Map<String, Integer> paramIndexMapping;
    /**
     * 用户权限
     */
    private List<String> userPermission;
    /**
     * 标记改方法是否需要 HttpServletRequest
     */
    private boolean needRequest = false;
    /**
     * 标记改方法是否需要 HttpServletResponse
     */
    private boolean needResponse = false;

    public boolean isNeedRequest() {
        return needRequest;
    }

    public void setNeedRequest(boolean needRequest) {
        this.needRequest = needRequest;
    }

    public boolean isNeedResponse() {
        return needResponse;
    }

    public void setNeedResponse(boolean needResponse) {
        this.needResponse = needResponse;
    }

    public Object getObject() {
        return object;
    }

    public void setObject(Object object) {
        this.object = object;
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }

    public Pattern getPattern() {
        return pattern;
    }

    public void setPattern(Pattern pattern) {
        this.pattern = pattern;
    }

    public Map<String, Integer> getParamIndexMapping() {
        return paramIndexMapping;
    }

    public void setParamIndexMapping(Map<String, Integer> paramIndexMapping) {
        this.paramIndexMapping = paramIndexMapping;
    }

    public List<String> getUserPermission() {
        return userPermission;
    }

    public void setUserPermission(List<String> userPermission) {
        this.userPermission = userPermission;
    }

    public Handler(Object object, Method method, Pattern pattern, List<String> userPermission) {
        this.object = object;
        this.method = method;
        this.pattern = pattern;
        this.paramIndexMapping = new HashMap<>(16);
        this.userPermission = userPermission;
    }
}
